package com.dh.cb;

import java.util.concurrent.CyclicBarrier;

public class LoadThread extends Thread {
    private LoadHandler loadHandler = null;
    private LoadTask loadTask = null;

    private CyclicBarrier cyclicBarrier;

    public LoadThread(LoadHandler loadHandler, CyclicBarrier cyclicBarrier) {
        this.loadHandler = loadHandler;
        this.cyclicBarrier = cyclicBarrier;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "   start");
        while (loadTask == null) {
            loadTask = loadHandler.poll();
            if (loadTask != null) {
                loadTask.work();
            }
            try {
                cyclicBarrier.await();
                loadTask = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


}
